#include <buola/gui.h>

#include <buola/gui/ctoolkit.h>
#include <buola/image/cfont.h>
#include <buola/image/cgc.h>

#include <buola/widgets/ctooltip.h>
#include <buola/widgets/ctheme.h>

namespace buola { namespace gui {

CToolTip::CToolTip(const std::wstring &pCaption)
{
    SetOpacity(0.85);
    SetWindowType(EWindowType::TOOLTIP);

    mFont=img::CFont::GetStock(L"control");

    get_default_theme()->SetBackground(this,BACKGROUND_TOOLTIP);

    RePos();
    SetCaption(pCaption);
}

CToolTip::~CToolTip()
{
}

void CToolTip::SetCaption(const std::wstring &pCaption)
{
    mCaption=pCaption;
    Shape();
}

void CToolTip::RePos()
{
    Move(get_toolkit()->GetMousePos()+CPoint_d(16,16));
}

void CToolTip::Shape()
{
    mTextLayout.SetDefaultFont(mFont);
    mTextLayout.SetText(mCaption);
    mTextLayout.SetWidth(200);
    mTextLayout.SetHeight(100);
    Resize(mTextLayout.GetSize()+CSize_d(4,4));
    Refresh();
}

///////////////// events //////////////////

void CToolTip::OnExpose(const CExposeEvent &pE)
{
    img::CGC *lGC=pE.mGC;

    lGC->SetFont(mFont);
    lGC->SetSource({0.0,0.0,0.0});

    lGC->Path().Rect({0,0},Size());
    lGC->StrokePath();

    mTextLayout.Draw(CPoint_d(2,2),lGC);
}

void CToolTip::OnMouseMove(const CMouseEvent &pE)
{
}

void CToolTip::OnMouseOut(const CMouseEvent &pE)
{
}

/*namespace gui*/ } /*namespace buola*/ }
